POV-Ray : Newsgroups : povray.advanced-users : Object Oriented POV code : Re: Object Oriented POV code Server Time
29 Jul 2024 18:28:46 EDT (-0400)
  Re: Object Oriented POV code  
From: Warp
Date: 22 Feb 2004 07:27:27
Message: <4038a02f@news.povray.org>
Christopher James Huff <cja### [at] earthlinknet> wrote:
> Pass everything by reference

  That can be problematic.

  Suppose you have something like this:

class ItemContainer
{
 private:
    Int numberOfItems;

 public:
    ...
    Int size() { return numberOfItems; } // <- returns a reference
    ...
};
...


ItemContainer container;
// add things to 'container'

Int foo = container.size(); // <- gets a *reference*
foo -= 100; // Ooops! The container breaks badly!

  The thing is that in principle the code is not doing anything malign
on purpose. It's only natural that you take eg. the size of the container
to a variable and then use this variable for example as a loop counter
(eg. to go through all the items in the container).
  The big problem is that since your variable is actually a reference
to the original 'numberOfItems' variable, you'll end up breaking the
container.

  I don't know enough about Java to know how this problem is avoided
there.

-- 
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.